package cn.wx.shop.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.wx.shop.dao.GoodsDao;
import cn.wx.shop.entity.Goods;
import cn.wx.shop.entity.page.Page;

@Service
public class GoodsService {

	@Autowired
	GoodsDao goodsDao;
	
	public int addGoods(Goods goods){
		return goodsDao.addGoods(goods);
	}
	
	/**
	 * 商品分页
	 * @param pageNo
	 * @return
	 */
	public Page<Goods> selectByPage(Integer pageNo){
		Page<Goods> pageInfo = new Page<Goods>(pageNo,2);
		pageInfo.setTotalRow(goodsDao.selectCountByPage());
		pageInfo.setList(goodsDao.selectByPage(pageInfo.getFromSize(), pageInfo.getPageSize()));
		return pageInfo;
	}
	
	public Goods selectById(Integer id){
		return goodsDao.selectById(id);
	}

	public int updateGoods(Goods goods) {
		return goodsDao.updateGoods(goods);
	}

	public List<Goods> getGoodsByCid(Integer cid) {
		return goodsDao.getGoodsByCid(cid);
	}
}
